#include "rtree.h"
#include <iostream>
using namespace std;
REALTYPE rects[][SIDES_NUM]= {
	{0,0,2,2},	
	{5,5,7,7},
	{8,5,9,6},
	{7,1,9,2},
	{2,2,3,3},
	{5,4,8,5}
};
REALTYPE	searchRects[][SIDES_NUM]={
	{6,4,8,6}

};
REALTYPE	deleteRects[][SIDES_NUM]={
	{7,1,9,2},
	{0,0,2,2},	
	{2,2,3,3},
	{5,5,7,7},
	{8,5,9,6},
	{5,4,8,5}
};
int deletedIDs[]={
	4,1,5,2,3,6
};
int SearchCallback(int id,void *pParam)
{
	static int i=0;
	i++;
	cout<<"Hit:"<<id<<endl;
	if(i>1)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}
int main(int argc,char *argv[])
{
	RTree rtree;
	RTree::MBR mbr;
	int i,j,hitCount;
	for(i=0;i<sizeof(rects)/(sizeof(REALTYPE)*SIDES_NUM);i++)
	{
		for(j=0;j<SIDES_NUM;j++)
		{
			mbr.bounds[j]=rects[i][j];
		}
		rtree.Insert(&mbr,i+1);
	}
	//Search
	/*for(i=0;i<sizeof(searchRects)/(sizeof(REALTYPE)*SIDES_NUM);i++)
	{
		for(j=0;j<SIDES_NUM;j++)
		{
			mbr.bounds[j]=searchRects[i][j];
		}
		hitCount=rtree.Search(&mbr,SearchCallback,NULL);
		cout<<"HitCount:"<<hitCount<<endl;
	}*/
	//Delete
	for(i=0;i<sizeof(deleteRects)/(sizeof(REALTYPE)*SIDES_NUM);i++)
	{
		for(j=0;j<SIDES_NUM;j++)
		{
			mbr.bounds[j]=deleteRects[i][j];
		}
		rtree.Delete(&mbr,deletedIDs[i]);
	}
}